package cn.lyjuan.android.demofive.ui.component.date_picker_dialog;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import cn.lyjuan.android.demofive.R;

import java.util.Calendar;

/**
 * Created by chad on 2016/1/19.
 */
public class DatePickerDialogActivity extends Activity {

    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setContentView(R.layout.ui_date_picker_dialog);

        text = (TextView) this.findViewById(R.id.ui_date_picker_dialog_text);
    }

    public void showDate(View v)
    {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog dialog = new DatePickerDialog(this, dateSetListener, year, month, day);
        dialog.show();
    }

    private DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            text.setText("时间：" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
        }
    };
}
